package protocol.SZ_2021;

import java.util.HashMap;

public class Handle2021SZ8F implements IHandle2021SZ {
    @Override
    public String handle(SZ_2021Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x02:
                return handle8f02(cmd);
            case 0x24:
                return handle8f24(cmd);
            case 0x25:
                return handle8f25(cmd);
            case 0x28:
                return handle8f28(cmd);
            case 0x46:
                return handle8f46(cmd);
            case 0x6e:
                return handle8f6e(cmd);
            case (byte) 0x92:
                return handle8F92(cmd);
            default:
                return "深标:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }

    private String handle8f02(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:删除司机");
        builder.append("\r\n");

        if (cmd.leftSize() < 19){
            builder.append("删除全部司机");
            builder.append("\r\n");
        }else{
            builder.append("司机列表：");
            builder.append("\r\n");
            do {
                builder.append("    从业资格证号:"+cmd.readString(19));
                builder.append("\r\n");
            }while (cmd.leftSize() >= 19);
        }

        return builder.toString();
    }

    private String handle8f24(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:休眠唤醒");
        builder.append("\r\n");
        builder.append("唤醒时长："+cmd.readInt(2));
        builder.append("\r\n");

        int type = cmd.readInt(4);
        builder.append("唤醒设备："+type);
        builder.append("\r\n");
        builder.append("    摄像头："+(type&0x01));
        builder.append("\r\n");
        builder.append("    多功能显示屏："+(type>>1&0x01));
        builder.append("\r\n");
        builder.append("    智能顶灯："+(type>>2&0x01));
        builder.append("\r\n");
        builder.append("    LED显示屏："+(type>>3&0x01));
        builder.append("\r\n");
        builder.append("    服务评价器："+(type>>4&0x01));
        builder.append("\r\n");
        builder.append("    卫星定位设备："+(type>>5&0x01));
        builder.append("\r\n");
        builder.append("    支付装置："+(type>>6&0x01));
        builder.append("\r\n");
        builder.append("    出租汽车安全模块TSM："+(type>>7&0x01));
        builder.append("\r\n");

        builder.append("    收音机："+(type>>8&0x01));
        builder.append("\r\n");
        builder.append("    数字电视："+(type>>9&0x01));
        builder.append("\r\n");
        builder.append("    空调："+(type>>10&0x01));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle8f25(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:通知相应外设进入休眠");
        builder.append("\r\n");

        int type = cmd.readInt(4);
        builder.append("唤醒设备："+type);
        builder.append("\r\n");
        builder.append("    摄像头："+(type&0x01));
        builder.append("\r\n");
        builder.append("    多功能显示屏："+(type>>1&0x01));
        builder.append("\r\n");
        builder.append("    智能顶灯："+(type>>2&0x01));
        builder.append("\r\n");
        builder.append("    LED显示屏："+(type>>3&0x01));
        builder.append("\r\n");
        builder.append("    服务评价器："+(type>>4&0x01));
        builder.append("\r\n");
        builder.append("    卫星定位设备："+(type>>5&0x01));
        builder.append("\r\n");
        builder.append("    支付装置："+(type>>6&0x01));
        builder.append("\r\n");
        builder.append("    出租汽车安全模块TSM："+(type>>7&0x01));
        builder.append("\r\n");

        builder.append("    收音机："+(type>>8&0x01));
        builder.append("\r\n");
        builder.append("    数字电视："+(type>>9&0x01));
        builder.append("\r\n");
        builder.append("    空调："+(type>>10&0x01));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle8f28(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:控制终端对指定时段的录像进行操作");
        builder.append("\r\n");

        builder.append("录像的起始时间："+cmd.readBCD(6));
        builder.append("\r\n");

        builder.append("录像的结束时间："+cmd.readBCD(6));
        builder.append("\r\n");

        int channel = cmd.readInt(2);
        if (channel>2){
            builder.append("通道号:内外摄像头");
        }else if (channel == 2){
            builder.append("通道号:内摄像头");
        }else if (channel == 1){
            builder.append("通道号:外摄像头");
        }else{
            builder.append("通道号:无");
        }
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"在终端上播放指定时段录像");
        list.put(1,"指定时段录像加锁");
        builder.append("录像操作："+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle8f46(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:平台下发司机交班及下班、充电状态LED屏显示信息");
        builder.append("\r\n");

        builder.append("车牌："+cmd.readString(9));
        builder.append("\r\n");

        builder.append("准许证号："+cmd.readString(19));
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(1,"双班司机交接班地点");
        list.put(2,"单班司机下班地点");
        list.put(3,"禁止交接班下班时间段");

        int num = cmd.readInt();
        for (int i = 0; i < num; i++) {
            int id = cmd.readInt();
            builder.append("    信息ID("+id+")："+list.getOrDefault(id,"未定义"));
            builder.append("\r\n");

            builder.append("    信息："+cmd.readString(cmd.readInt()));
            builder.append("\r\n");
        }

        return builder.toString();
    }

    private String handle8f6e(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:上报数据汇总查询");
        builder.append("\r\n");
        builder.append("统计日期："+cmd.readBCD(3));
        builder.append("\r\n");
        return builder.toString();
    }

    private String handle8F92(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:平台下发出租小汽车道路运输证");
        builder.append("\r\n");

        builder.append("从业资格证卡号："+cmd.readString(19));
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(1,"出租小汽车道路运输证");
        list.put(2,"出租起床驾驶证");

        int type = cmd.readInt();

        builder.append("二维码类型("+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        builder.append("二维码内容:"+cmd.readString(cmd.leftSize()));
        builder.append("\r\n");

        return builder.toString();
    }


}
